package com.design.movieticket.common.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

import com.design.movieticket.common.base.constant.GlobalConst;

import com.design.movieticket.login.entity.LoginUser;
import org.apache.ibatis.reflection.MetaObject;

import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;

@Component
public class MetaHandler implements MetaObjectHandler {

    @Resource
    private LoginUser loginUser;

    /** 新增的时候自动填充 */
    @Override
    public void insertFill(MetaObject metaObject) {
//        this.setFieldValByName("createBy", loginUser.getUser().getId(), metaObject);
//        this.setFieldValByName("createTime", LocalDateTime.now(GlobalConst.ZONE_ID), metaObject);
//        this.setFieldValByName("updateBy", loginUser.getUser().getId(), metaObject);
//        this.setFieldValByName("updateTime", LocalDateTime.now(GlobalConst.ZONE_ID), metaObject);
    }

    /** 更新的时候自动填充 */
    @Override
    public void updateFill(MetaObject metaObject) {
//        this.setFieldValByName("updateBy", loginUser.getUser().getId(), metaObject);
//        metaObject.setValue("updateTime",null);
//        this.setFieldValByName("updateTime", LocalDateTime.now(GlobalConst.ZONE_ID), metaObject);
    }
}
